<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <!--查询区-->
      <div class="table-page-search-wrapper">
        <a-form :form="form" layout="inline">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="数据类型">
                <a-select show-search placeholder="请选择" v-decorator="['dataType',{rules: []}]">
                  <a-select-option value="">全部</a-select-option>
                  <a-select-option v-for="(value, key) in this.log_group" :key="key">
                    ({{ key }}){{ value.dictValue }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="发起人">
                <a-input v-decorator="['applicant',{rules: []}]" placeholder="请输入发起人"/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="审核类型">
                <a-select show-search placeholder="请选择" v-decorator="['auditType',{rules: []}]">
                  <a-select-option value="">全部</a-select-option>
                  <a-select-option v-for="(value, key) in this.log_type" :key="key">
                    ({{ key }}){{ value.dictValue }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="审核人">
                <a-input v-decorator="['auditUser',{rules: []}]" placeholder="请输入审核人"/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="审核状态">
                <a-select show-search placeholder="请选择" v-decorator="['auditState',{rules: []}]">
                  <a-select-option value="">全部</a-select-option>
                  <a-select-option v-for="(value, key) in this.audit_state" :key="key">
                    ({{ key }}){{ value.dictValue }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item label="创建时间">
                <a-input type="hidden" v-decorator="['createTime',{initialValue:initCreateTime+'',rules: []}]"/>
                <a-range-picker
                  allowClear
                  :defaultValue="initCreateTime"
                  format="YYYY-MM-DD HH:mm:ss"
                  show-time
                  @change="onCreateTimeChange"
                />
              </a-form-item>
            </a-col>
            <!--隐藏查询条件-->
            <template v-if="advanced">
            </template>
            <a-col :md="!advanced && 8 || 24" :sm="24">
              <span class="table-page-search-submitButtons" :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
                <a-button type="primary" @click="handleSearch">查询</a-button>
                <a-button style="margin-left: 8px" @click="handleReset">重置</a-button>
                <a @click="() => this.advanced = !this.advanced" style="margin-left: 8px">
                  {{ advanced ? '收起' : '展开' }}
                  <a-icon :type="advanced ? 'up' : 'down'"/>
                </a>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!--全局操作-->
      <div class="table-operator">
        <a-button type="primary" icon="download" @click="handleDownload" v-if="hasPerm('admin:system:auditinfo:download')">下载</a-button>
        <a-dropdown v-if="selectedRowKeys.length > 0">
          <a-menu slot="overlay">
            <a-menu-item key="auditingPass" @click="handleMenuClick" v-if="hasPerm('admin:system:auditinfo:auditing')">
              <a-icon type="check"/>
              审核通过
            </a-menu-item>
            <a-menu-item key="auditingRefuse" @click="handleMenuClick" v-if="hasPerm('admin:system:auditinfo:auditing')">
              <a-icon type="close"/>
              审核拒绝
            </a-menu-item>
          </a-menu>
          <a-button style="margin-left: 8px">
            批量操作
            <a-icon type="down"/>
          </a-button>
        </a-dropdown>
      </div>
      <!--汇总-->
      <!--数据表格-->
      <a-table
        :rowKey=" (record => record.id)"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="pagination"
        :rowSelection="rowSelection"
        :loading="loading"
        @change="tableChange"
        bordered
      >
        <!--字段扩展显示customRender-->
        <template v-slot:dataType="text">
          {{ dictFilter(text,'log_group') }}
        </template>
        <template v-slot:auditType="text">
          {{ dictFilter(text,'log_type') }}
        </template>
        <template v-slot:auditState="text">
          {{ dictFilter(text,'audit_state') }}
        </template>
        <!--行操作-->
        <template v-slot:action="text, record">
          <span>
            <a href="javascript:" @click="handleInfo(record)" v-if="hasPerm('admin:system:auditinfo:info')">详情</a>
            <a-divider type="vertical"/>
            <template v-if="record.auditState === 2">
              <a-popconfirm title="确定通过吗？" @confirm="handleAuditing(record,true)" v-if="hasPerm('admin:system:auditinfo:auditing')">
                <a-icon slot="icon" type="question-circle-o" style="color: red"/>
                <a href="javascript:">通过</a>
              </a-popconfirm>
              <a-divider type="vertical"/>
              <a-popconfirm title="确定拒绝吗？" @confirm="handleAuditing(record,false)" v-if="hasPerm('admin:system:auditinfo:auditing')">
                <a-icon slot="icon" type="question-circle-o" style="color: red"/>
                <a href="javascript:">拒绝</a>
              </a-popconfirm>
              <a-divider type="vertical"/>
            </template>
          </span>
        </template>
      </a-table>
      <!--自定义组件-->
      <info ref="info" @refresh="refresh" />
    </a-card>
  </page-header-wrapper>
</template>
<script>
  import curdMixins from '@/utils/mixins/curdMixins'
  import { getList, downloadFile, auditingByIds } from '@/api/system/auditinfo'
  import info from './info'
  export default {
    mixins: [curdMixins],
    components: {
      info
    },
    data () {
      this.columns = [
        {
          title: '数据类型',
          dataIndex: 'dataType',
          scopedSlots: { customRender: 'dataType' }
        },
        {
          title: '审核类型',
          dataIndex: 'auditType',
          scopedSlots: { customRender: 'auditType' }
        },
        {
          title: '变更后数据',
          dataIndex: 'dataNew',
          ellipsis: true
        },
        {
          title: '发起人',
          dataIndex: 'applicant'
        },
        {
          title: '审核人',
          dataIndex: 'auditUser'
        },
        {
          title: '审核状态',
          dataIndex: 'auditState',
          scopedSlots: { customRender: 'auditState' }
        },
        {
          title: '创建时间',
          dataIndex: 'createTime'
        },
        {
          title: '操作',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' }
        }
      ]
      return {
        // 多选操作
        multiOperator: [
          {
            key: 'auditingPass',
            method: auditingByIds,
            ext: true
          },
          {
            key: 'auditingRefuse',
            method: auditingByIds,
            ext: false
          }
        ],
        log_group: {},
        log_type: {},
        audit_state: {},
        initCreateTime: [this.moment().add(-1, 'd').format('YYYY-MM-DD'), this.moment().add(1, 'd').format('YYYY-MM-DD')],
        genTemp: null
      }
    },
    created () {
      // 获取字典数据
      this.getDictValue('log_group').then(res => {
        this.log_group = res.data
      })
      // 获取字典数据
      this.getDictValue('log_type').then(res => {
        this.log_type = res.data
      })
      // 获取字典数据
      this.getDictValue('audit_state').then(res => {
        this.audit_state = res.data
      })
    },
    methods: {
      // 表单参数过滤,mixins调用
      filterForm (values) {
        return values
      },
      // 列表查询,mixins调用
      list (param) {
        return getList(param)
      },
      // 下载list,mixins调用
      download (param) {
        return downloadFile(param)
      },
      // 审核,mixins调用
      auditing (record, pass) {
        return auditingByIds({ ids: [record.id] }, pass)
      },
      // 日期格式转换
      onCreateTimeChange (date, dateString) {
         this.form.setFieldsValue({ 'createTime': dateString + '' })
      }
    }
  }
</script>
<style scoped>
</style>
